package com.ants.modules.articleResource.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.ants.common.annotation.AutoLog;
import com.ants.common.system.query.QueryGenerator;
import com.ants.common.system.result.Result;
import com.ants.modules.articleResource.entity.ArticleResource;
import com.ants.modules.articleResource.service.ArticleResourceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * TODO
 * Author Chen
 * Date   2021/9/7 18:44
 */

@Slf4j
@Api(tags = "关注用户")
@RestController
@RequestMapping("/articleResource")
public class ArticleResourceController {

    @Autowired
    ArticleResourceService articleResourceService;

    @AutoLog(value = "关注用户-查询关注列表")
    @ApiOperation(value = "关注用户-查询关注列表", notes = "关注用户-查询关注列表")
    @GetMapping("/list")
    public Result<?> queryPageList(ArticleResource articleResource,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<ArticleResource> queryWrapper = QueryGenerator.initQueryWrapper(articleResource, req.getParameterMap());
        String username = StpUtil.getLoginIdAsString();
        queryWrapper.eq("create_by", username);
        queryWrapper.orderByDesc("create_time");
        Page<ArticleResource> page = new Page<ArticleResource>(pageNo, pageSize);
        IPage<ArticleResource> pageList = articleResourceService.page(page, queryWrapper);
        return Result.ok(pageList);
    }


}
